<template>
  <a-drawer
      :title="title"
      :width="800"
      placement="right"
      :closable="false"
      @close="close"
      :visible="visible"
  >

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户的id号">
          <a-input placeholder="请输入用户的id号" v-decorator="['userId', validatorRules.userId ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户的姓名">
          <a-input placeholder="请输入用户的姓名" v-decorator="['userXm', validatorRules.userXm ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户的昵称">
          <a-input placeholder="请输入用户的昵称" v-decorator="['userNc', validatorRules.userNc ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户的头像链接">
          <a-input placeholder="请输入用户的头像链接" v-decorator="['userTxlj', validatorRules.userTxlj ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户的手机号">
          <a-input placeholder="请输入用户的手机号" v-decorator="['userSjh', validatorRules.userSjh ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户密码">
          <a-input placeholder="请输入用户密码" v-decorator="['userMm', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户照片链接">
          <a-input placeholder="请输入用户照片链接" v-decorator="['userZplj', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户身份证照片链接">
          <a-input placeholder="请输入用户身份证照片链接" v-decorator="['userSfzlj', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户驾驶证链接">
          <a-input placeholder="请输入用户驾驶证链接" v-decorator="['userJszlj', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户身份证号">
          <a-input placeholder="请输入用户身份证号" v-decorator="['userSfzh', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户注册的日期时间">
          <a-input placeholder="请输入用户注册的日期时间" v-decorator="['userZcrqsj', validatorRules.userZcrqsj ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户的状态，默认是0,，0表示正常，1表示删除，2表示禁用">
          <a-input-number v-decorator="[ 'userZt', validatorRules.userZt ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户实名认证状态，默认是0 ，0表示没有认证，1表示认证">
          <a-input-number v-decorator="[ 'userSmrz', validatorRules.userSmrz ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="车辆认证，默认是0,0表示没有认证，1表示认证">
          <a-input-number v-decorator="[ 'userClrz', validatorRules.userClrz ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户实名认证的日期时间">
          <a-input placeholder="请输入用户实名认证的日期时间" v-decorator="['userSmrzrqsj', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="车辆认证的日期时间">
          <a-input placeholder="请输入车辆认证的日期时间" v-decorator="['userClrzrqsj', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户身份标识，默认为0,1表示司机，2表示货主">
          <a-input-number v-decorator="[ 'userSfbz', validatorRules.userSfbz ]" />
        </a-form-item>
		
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "UserModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        userId:{rules: [{ required: true, message: '请输入用户的id号!' }]},
        userXm:{rules: [{ required: true, message: '请输入用户的姓名!' }]},
        userNc:{rules: [{ required: true, message: '请输入用户的昵称!' }]},
        userTxlj:{rules: [{ required: true, message: '请输入用户的头像链接!' }]},
        userSjh:{rules: [{ required: true, message: '请输入用户的手机号!' }]},
        userZcrqsj:{rules: [{ required: true, message: '请输入用户注册的日期时间!' }]},
        userZt:{rules: [{ required: true, message: '请输入用户的状态，默认是0,，0表示正常，1表示删除，2表示禁用!' }]},
        userSmrz:{rules: [{ required: true, message: '请输入用户实名认证状态，默认是0 ，0表示没有认证，1表示认证!' }]},
        userClrz:{rules: [{ required: true, message: '请输入车辆认证，默认是0,0表示没有认证，1表示认证!' }]},
        userSfbz:{rules: [{ required: true, message: '请输入用户身份标识，默认为0,1表示司机，2表示货主!' }]},
        },
        url: {
          add: "/user/user/add",
          edit: "/user/user/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'userId','userXm','userNc','userTxlj','userSjh','userMm','userZplj','userSfzlj','userJszlj','userSfzh','userZcrqsj','userZt','userSmrz','userClrz','userSmrzrqsj','userClrzrqsj','userSfbz'))
		  //时间格式化
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>